import { createStore } from 'redux'

const initState = {
  list: [{
    title: "真不错",
    time: '2024年',
    id: 1
  }]
  
}

const reducer = (state = initState, action) => {
  if(action.type === 'add') {
    return { list: [...state.list, { title: action.payload, time: new Date().toLocaleString(), id: new Date().getTime()  }] }
  }

  if(action.type === 'del') {
    return {
      list: state.list.filter(v => v.id !== action.payload)
    }
  }
  return state
}

export const store = createStore(reducer);
